/**
 * ...
 * @author Franco Ponticelli
 */

package uform.ui.comp;

import uform.property.IReadProperty;
import uform.property.IProperty;
import uform.property.Property;
import uform.ui.comp.Container;
using Types;

class Component implements IComponent
{
	static var nextid = 0;
	public var id(getId, null) : String;
	public var parent(default, null) : IReadProperty<Container>;
	public var visible(default, null) : IProperty<Bool>;
	public var enabled(default, null) : IProperty<Bool>;
	private var _parent : IProperty<Container>;
	private function new()
	{
		this.parent = _parent = new Property();
		this.visible = new Property(true);
		this.enabled = new Property(true);
	}
	
	public function dispose()
	{
		if (!parent.isNull())
			parent.get().remove(this);
		parent.onChange.clear();
		parent = _parent = null;
		visible.onChange.clear();
		visible = null;
		enabled.onChange.clear();
		enabled = null;
	}
	
	public function path()
	{
		return parent.isNull() ? "" : parent.get().path();
	}
	
	public function toString()
	{
		return this.className() + " (#" + id + ")";
	}
	
	function _id() : String
	{
		return throw "must override";
	}
	
	function getId()
	{
		return ((!parent.isNull()) ? parent.get().id : "") + _id();
	}
}